----------
--Query

local _G = _G


-- LOCAL VARS--
local tonumber = _G.tonumber
local GetItemInfo = _G.GetItemInfo
local GetSpellInfo = _G.GetSpellInfo


-- GENERIC PRINT --
local function printitem(message,frame)
	frame = frame or _G.DEFAULT_CHAT_FRAME
	frame:AddMessage(message)
end

-- SLASH QUERYING --
_G.SLASH_ITEMQUERY1 = "/item";
_G.SLASH_ITEMQUERY2 = "/wupin";
_G.SLASH_SPELLQUERY1 = "/jineng";
_G.SLASH_QUESTQUERY1 = "/quest";
_G.SLASH_QUESTQUERY2 = "/renwu";
_G.SLASH_ENCHANTQUERY1 = "/enchant";
_G.SLASH_ENCHANTQUERY2 = "/shangye";

function _G.SlashCmdList.ITEMQUERY(ID)
	if tonumber(ID) then
		local _,link = GetItemInfo(ID)
		if link then
			printitem("|cffFFFF7F[\231\137\169\229\147\129|r|cffFF7F7F\230\159\165\232\175\162|r|cffFFFF7F]|r ItemID \"|cff9999FF"..ID.."|r\" \229\156\168\231\188\147\229\173\152\228\184\173\230\137\190\229\136\176: "..link..".")
		else
			printitem("|cffFFFF7F[\231\137\169\229\147\129|r|cffFF7F7F\230\159\165\232\175\162|r|cffFFFF7F]|r ItemID \"|cff9999FF"..ID.."|r\" \230\156\170\229\156\168\231\188\147\229\173\152\228\184\173\230\137\190\229\136\176. |cffFF0000|Hitem:"..ID..":0:0:0:0:0:0:0|h[\231\130\185\229\135\187\230\159\165\232\175\162\231\137\169\229\147\129]|r.")
		end
	else
		printitem("|cffFFFF7F[\231\137\169\229\147\129|r|cffFF7F7F\230\159\165\232\175\162|r|cffFFFF7F]|r |cffFF3333\233\148\153\232\175\175:|r \230\151\160\230\149\136\231\154\132\232\190\147\229\133\165; ItemID\229\191\133\233\161\187\230\152\175\228\184\128\228\184\170\230\149\176\229\128\188.")
	end
end
function _G.SlashCmdList.SPELLQUERY(ID)
	if tonumber(ID) then
	local spellName = GetSpellInfo(ID)
		if spellName then
			printitem("|cffFFFF7F[\230\138\128\232\131\189|r|cffFF7F7F\230\159\165\232\175\162|r|cffFFFF7F]|r SpellID \"|cff9999FF"..ID.."|r\" \229\183\178\230\159\165\232\175\162\229\136\176: ".."|cff71d5ff|Hspell:"..ID.."|h["..spellName.."]|r.")
		else
			printitem("|cffFFFF7F[\230\138\128\232\131\189|r|cffFF7F7F\230\159\165\232\175\162|r|cffFFFF7F]|r SpellID \"|cff9999FF"..ID.."|r \228\184\141\230\152\175\228\184\128\228\184\170\230\156\137\230\149\136\230\138\128\232\131\189")
		end
	else
		printitem("|cffFFFF7F[\230\138\128\232\131\189|r|cffFF7F7F\230\159\165\232\175\162|r|cffFFFF7F]|r |cffFF3333\233\148\153\232\175\175:|r \230\151\160\230\149\136\231\154\132\232\190\147\229\133\165; SpellID\229\191\133\233\161\187\230\152\175\228\184\128\228\184\170\230\149\176\229\128\188.")
	end
end
function _G.SlashCmdList.QUESTQUERY(ID)
	local tip = CreateFrame("GameTooltip", "JYTooltip", UIParent, "GameTooltipTemplate");
	tip:ClearLines();
	tip:SetOwner(UIParent, "ANCHOR_NONE");
	tip:SetHyperlink("quest:"..ID);
	local questName;
	if tip:NumLines() > 0 then questName = JYTooltipTextLeft1:GetText() end
	--if questName then ChatFrame1:AddMessage(questName) end
	if tonumber(ID) then
		if questName then
			printitem("|cffFFFF7F[\228\187\187\229\138\161|r|cffFF7F7F\230\159\165\232\175\162|r|cffFFFF7F]|r QuestID \"|cff9999FF"..ID.."|r\" \229\183\178\230\159\165\232\175\162\229\136\176: ".."|cffffff00|Hquest:"..ID.."|h["..questName.."]|r.")
		else
			printitem("|cffFFFF7F[\228\187\187\229\138\161|r|cffFF7F7F\230\159\165\232\175\162|r|cffFFFF7F]|r QuestID \"|cff9999FF"..ID.."|r \230\156\170\229\156\168\231\188\147\229\173\152\228\184\173\230\137\190\229\136\176. |cffff0000|Hquest:"..ID.."|h[\231\130\185\229\135\187\230\159\165\232\175\162\228\187\187\229\138\161]|r.")
		end
	else
		printitem("|cffFFFF7F[\228\187\187\229\138\161|r|cffFF7F7F\230\159\165\232\175\162|r|cffFFFF7F]|r |cffFF3333\233\148\153\232\175\175:|r \230\151\160\230\149\136\231\154\132\232\190\147\229\133\165; QuestID\229\191\133\233\161\187\230\152\175\228\184\128\228\184\170\230\149\176\229\128\188.")
	end
end
function _G.SlashCmdList.ENCHANTQUERY(ID)
	local tip = CreateFrame("GameTooltip", "JYTooltip", UIParent, "GameTooltipTemplate");
	tip:ClearLines();
	tip:SetOwner(UIParent, "ANCHOR_NONE");
	tip:SetHyperlink("enchant:"..ID);
	local enchantName;
	if tip:NumLines() > 0 then enchantName = JYTooltipTextLeft1:GetText() end
	if tonumber(ID) then
		if enchantName then
			printitem("|cffFFFF7F[\229\149\134\228\184\154|r|cffFF7F7F\230\159\165\232\175\162|r|cffFFFF7F]|r EnchantID \"|cff9999FF"..ID.."|r\" \229\183\178\230\159\165\232\175\162\229\136\176: ".."|cff71d5ff|Henchant:"..ID.."|h["..enchantName.."]|r.")
		else
			printitem("|cffFFFF7F[\229\149\134\228\184\154|r|cffFF7F7F\230\159\165\232\175\162|r|cffFFFF7F]|r EnchantID \"|cff9999FF"..ID.."|r \228\184\141\230\152\175\228\184\128\228\184\170\230\156\137\230\149\136\229\149\134\228\184\154\230\138\128\232\131\189")
		end
	else
		printitem("|cffFFFF7F[\229\149\134\228\184\154|r|cffFF7F7F\230\159\165\232\175\162|r|cffFFFF7F]|r |cffFF3333\233\148\153\232\175\175:|r \230\151\160\230\149\136\231\154\132\232\190\147\229\133\165; EnchantID\229\191\133\233\161\187\230\152\175\228\184\128\228\184\170\230\149\176\229\128\188.")
	end
end

---------
--[[便捷使用种族语言]]

local l_SECOND_LANGUAGE;


SlashCmdList["SlashLanguage"] = function(msg)
	if (l_SECOND_LANGUAGE == nil) then
		l_SECOND_LANGUAGE = (GetLanguageByIndex(2) or GetLanguageByIndex(1));
	end
	
	local chatType, realMsg = msg:match("^%[([^%]]+)%] (.+)");
	local target;
	if (chatType ~= nil) then
		msg = realMsg;
		chatType = chatType:lower();
		local realChatType, potentialTarget = chatType:match("^(%S+) (.+)");
		if (realChatType ~= nil) then
			chatType = realChatType;
			target = (GetChannelName(potentialTarget) or potentialTarget);
		end
	else
		local editBox = this;
		chatType = (editBox:GetAttribute("chatType") or editBox.chatType);
		target = (editBox:GetAttribute("tellTarget") or editBox.tellTarget);
	end
	
	SendChatMessage(msg, chatType, l_SECOND_LANGUAGE, target);
end

SLASH_SlashLanguage1 = ("/lan");


----------
--[[!EVA_TxtMessage 提示消息]]
--创建并初始化插件
local EVA_TextMessage = EVA.Addon:New()

--设置插件相关描述
EVA_TextMessage.Name ="Commander Text"
EVA_TextMessage.Version ="0.1"
EVA_TextMessage.Description ="使用 /tip 显示文本. By 昏睡墨鱼. URL[http://wiki.cwowaddon.com/]"

--将插件添加到插件注册表中
EVA.AddonRegistry:Add(EVA_TextMessage)

function PrintTextMessage(msg)
	local text = msg.Slash_Arg
	--添加颜色
	text = "|cff7fff7f".. text .."|r";
	--显示文本
	DEFAULT_CHAT_FRAME:AddMessage(text);
end

	--创建功能集
local TextMessage = {
	RequestTypes = {"SlashCommand"},
	SlashCommands = {"/tip"},
	Commands = {
		{Function = PrintTextMessage},
	}
}

--将功能集合添加到插件中
EVA_TextMessage:Add(EVA.Block:New(TextMessage))


----------
--[[库存查询]]
local origOnTooltipSetItem = GameTooltip:GetScript("OnTooltipSetItem")
GameTooltip:SetScript("OnTooltipSetItem", function(...)
	local item = select(2, GameTooltip:GetItem())
	if item then
		local bags, all = GetItemCount(item), GetItemCount(item, true)
		if all > 0 then
			GameTooltip:AddDoubleLine("\229\133\177\230\156\137 "..all, "(\232\131\140\229\140\133: "..bags.." / \233\147\182\232\161\140: "..(all-bags)..")")
		end
	end
	return origOnTooltipSetItem(GameTooltip, ...)
end)

----------
--[[竞技场点数换算]]

function ArenaPoints_CheckNum(num)
	if num <= 0 then
		return 1
	else
		return num
	end
end

function Rating2Points(rating)
	rating = tonumber(rating) or 0
	local points
	if rating <= 1500 then
		points = 0.22 * rating + 14
	else
		points =  1511.26 / ( 1 + 1639.28 * 2.71828 ^(-0.00412*rating) )
	end
	return floor(points), floor(points*0.88), floor(points*0.76)
end

function Points2Rating(points)
	points = tonumber(points) or 0
	local Hrating5, Hrating3, Hrating2, Lrating5, Lrating3, Lrating2, rating5, rating3, rating2
	Hrating5 = math.log( ArenaPoints_CheckNum((1511.26 / points - 1) / 1639.28) ) / -0.00412
	Hrating3 = math.log( ArenaPoints_CheckNum((1511.26 * 0.88 / points - 1) / 1639.28) ) / -0.00412
	Hrating2 = math.log( ArenaPoints_CheckNum((1511.26 * 0.76 / points - 1) / 1639.28) ) / -0.00412
	Lrating5 = max((points - 14) / 0.22, 0)
	Lrating3 = max((points/0.88 - 14) / 0.22, 0)
	Lrating2 = max((points/0.76 - 14) / 0.22, 0)
	if points > 344 then
		rating5, rating3, rating2 = Hrating5, Hrating3, Hrating2
	elseif points > 303 then
		rating5, rating3, rating2 = Lrating5, Hrating3, Hrating2
	elseif points > 261 then
		rating5, rating3, rating2 = Lrating5, Lrating3, Hrating2
	else
		rating5, rating3, rating2 = Lrating5, Lrating3, Lrating2
	end
	return ceil(rating5), ceil(rating3), ceil(rating2)
end

ArenaPoints = {}
hooksecurefunc("PVPTeam_Update", function ()
	local button, id, teamSize, teamRating
	for i = 1, MAX_ARENA_TEAMS do
		button = getglobal("PVPTeam"..i)
		id = button:GetID()
		if id and id > 0 then
			teamSize, teamRating = select(2, GetArenaTeam(id))
			ArenaPoints[5], ArenaPoints[3], ArenaPoints[2] = Rating2Points(teamRating)
			if not button.points then
				button.points = button:CreateFontString(nil, "ARTWORK", "GameFontNormal")
				button.points:SetFont(STANDARD_TEXT_FONT, 15, "OUTLINE")
				button.points:SetPoint("BOTTOMLEFT", "PVPTeam"..i.."DataName", "BOTTOMLEFT", 0, -22)
			end
			button.points:SetText("|cffa0ffa0(" .. (ArenaPoints[teamSize] or "N/A") ..")")
		end
	end
end)

hooksecurefunc("ChatFrame_OnEvent", function(event)
	if event == "CHAT_MSG_WHISPER" then
		if strlower(strsub(arg1,1,3)) == "r2p" then
			local rating = select(3, strfind(strlower(arg1),"r2p%s+(%d+)"))
			local points5, points3, points2 =Rating2Points(rating)
			local PREFIX = " <等级" .. (rating or 0) ..">"
			SendChatMessage(PREFIX .. "  2v2  " .. points2 .. "分", "WHISPER", nil, arg2)
			SendChatMessage(PREFIX .. "  3v3  " .. points3 .. "分", "WHISPER", nil, arg2)
			SendChatMessage(PREFIX .. "  5v5  " .. points5 .. "分", "WHISPER", nil, arg2)
			return
		end
		if strlower(strsub(arg1,1,3)) == "p2r" then
			local points = select(3, strfind(strlower(arg1),"p2r%s+(%d+)"))
			local rating5, rating3, rating2 = Points2Rating(points)
			local PREFIX = " <得分" .. (points or 0) ..">"
			SendChatMessage(PREFIX .. "  2v2  等级" .. rating2, "WHISPER", nil, arg2)
			SendChatMessage(PREFIX .. "  3v3  等级" .. rating3, "WHISPER", nil, arg2)
			SendChatMessage(PREFIX .. "  5v5  等级" .. rating5, "WHISPER", nil, arg2)
		end
	end
end)

----------
--[[ 竞技场结束 抓图
local IsScreenShot = false
local InstanceType = nil
local Aframe = CreateFrame("Frame")
Aframe:Hide()
Aframe:RegisterEvent("ZONE_CHANGED_NEW_AREA")
Aframe:RegisterEvent("UPDATE_BATTLEFIELD_STATUS")
Aframe:SetScript("OnEvent", function()
	local type = select(2, IsInInstance())
	if( type == "arena" and type ~= InstanceType ) then
		IsScreenShot = false
	elseif( type ~= "arena" and InstanceType == "arena" ) then
		IsScreenShot = true
	elseif (type == "arena" and GetBattlefieldWinner()~=nil and IsScreenShot==false) then
		IsScreenShot = true
		if( not WorldStateScoreFrame:IsVisible() ) then
			ShowUIPanel(WorldStateScoreFrame)
		end
		Screenshot()
	end
	InstanceType = type
end)]]

----------
--[[專業技能鏈接大全]]
local FOR_BUILD=9464  --GetBuildInfo()
WarbabyTradeLinkData = {}

SLASH_WARBABY_TRADE_LINK1 = "/tradelink";
SLASH_WARBABY_TRADE_LINK2 = "/tl";
SlashCmdList["WARBABY_TRADE_LINK"] = function (cmd) 
	local color = "|cff7F7Fff";
	if(cmd=="CLEAR") then
		WarbabyTradeLinkData = {};
		DEFAULT_CHAT_FRAME:AddMessage(color.."Warbaby'sTradeLink數據已經清空，請重新收集。|r");
		return;
	end
	DEFAULT_CHAT_FRAME:AddMessage(color.."專業技能鏈接大全 作者 : Warbaby @ 聖光之願 <冰封十字軍>");
	DEFAULT_CHAT_FRAME:AddMessage(color.."  * 如果沒有某種技能, 請讓朋友發一次鏈接|r");
	DEFAULT_CHAT_FRAME:AddMessage(color.."  * 如果遊戲更新導致鏈接失效, 請運行'/tl CLEAR'清除過期數據|r");
	local curr = tonumber(cmd) or 450;
	local k,v,i,all;
	all = "";
	for k,v in pairs(WarbabyTradeLinkData) do
		local s = format("%0"..v.len.."d", 0);
		all = all..(" |c"..v.color.."|Htrade:"..v.id..":"..curr..":450:"..v.uid..":"..string.gsub(s,"0","/").."|h["..v.name.."]|h|r");
	end
	DEFAULT_CHAT_FRAME:AddMessage(all);
end


function WBTradeLink_GetTradeLink(self, message)
	if message then
		--ChatFrame2:AddMessage(string.gsub(message, "|", "$"));
		--if(string.find(message, "%|Htrade:")) then ChatFrame1:AddMessage(string.gsub(message, "|", "$")); end
		--if(string.find(message, "%|Htrade:")) then ChatFrame1:AddMessage("-------------"); end
		while(true) do
			local start, finish, color, trade, id, uid, list, name = string.find(message, "%|c(%x+)%|H(trade):(%d-):%d-:%d-:(%x-):([^|:]+)%|h%[([^%]]-)%]%|h%|r");
			if(not start) then
				start, finish, trade, color, id, uid, list, name = string.find(message, "{CLINK:(trade):(%x+):(%d-):%d-:%d-:(%x-):([^|:]+):([^}]-)}");
			end
			if(start) then
				--ChatFrame1:AddMessage(color..", "..trade..", "..id..", "..uid..", "..strlen(list)..", "..name);
				WarbabyTradeLinkData[name] = {
					["id"] = id,
					["uid"] = uid,
					["len"] = strlen(list),
					["name"] = name,
					["color"] = color,
				}
				message = string.sub(message, finish);
			else
				break;
			end
		end
	end
end

local i;
for i=1, 7 do
	if(getglobal("ChatFrame"..i)) then
		hooksecurefunc(getglobal("ChatFrame"..i), "AddMessage", WBTradeLink_GetTradeLink)
	end
end



local function SetOrHookScript(frame, scriptName, func)
	if( frame:GetScript(scriptName) ) then
		frame:HookScript(scriptName, func);
	else
		frame:SetScript(scriptName, func);
	end
end


TradeSkillFrame_LoadUI()

for i=1,20 do
	local btn = getglobal("TradeSkillSkill"..i);
	if btn then
		SetOrHookScript(btn, "OnEnter", function (self)
			local id = self:GetID();
			local skillName, skillType, numAvailable, isExpanded, altVerb = GetTradeSkillInfo(id);
			if(skillType=="header") then 
				GameTooltip:Hide();
				CursorUpdate(self);
			else
				GameTooltip:SetOwner(self, "ANCHOR_RIGHT");
				GameTooltip:SetTradeSkillItem(id);
				--GameTooltip:Hide();
				CursorUpdate(self);

				local numReagents = GetTradeSkillNumReagents(id);
				if(numReagents > 0) then
					GameTooltip:AddLine("-----------------------");
					local i;
					for i=1, numReagents, 1 do
						local reagentName, reagentTexture, reagentCount, playerReagentCount = GetTradeSkillReagentInfo(id, i);
						if(reagentName) then
							GameTooltip:AddLine(reagentName.."("..playerReagentCount.."/"..reagentCount..")");
						end
					end
					GameTooltip:Show();
				end
			end;

		end)

		SetOrHookScript(btn, "OnLeave", function (self)
			GameTooltip:Hide();
		end)

		btn:RegisterForClicks("LeftButtonUp","RightButtonUp");

		SetOrHookScript(btn, "OnClick", function (self, button)
			if ( IsModifiedClick() and button=="RightButton") then
				local link = GetTradeSkillRecipeLink(self:GetID())
				if link then
					local _, _, id = string.find(link, "%|c%x+%|Henchant:(%d-)%|h%[[^%]]-%]%|h%|r");
					id = "http://www.wowhead.com/?spell="..id;
					ChatFrameEditBox:Show();
					ChatFrameEditBox:SetText(id);
					ChatFrameEditBox:HighlightText(0, -1);
				end
			end
		end)
	end
end

local function GetMaskChar(b) --0-25(A-Z) 26-51(a-z) (52-61)0-9 62(+) 63(/)
	return strchar( b<26 and b+65 or b<52 and b-26+97 or b<62 and b-52+48 or b==62 and 43 or 47)
end

local function GetMaskByte(b)
	return b==43 and 62 or b==47 and 63 or b<=57 and b-48+52 or b<=90 and b-65 or b<=122 and b-97+26
end

TradeSkillLinkButton:RegisterForClicks("LeftButtonUp","RightButtonUp");
SetOrHookScript(TradeSkillLinkButton, "OnClick", function(self, button)
	if(button=="RightButton") then
		local link=GetTradeSkillListLink();
		if link then
			local start, finish, color, trade, id, uid, list, name = string.find(link, "%|c(%x+)%|H(trade):(%d-):%d-:%d-:(%x-):([^|:]+)%|h%[([^%]]-)%]%|h%|r");
			local l2 = ""
			local i
			for i=1, #list do
				local b = GetMaskByte(strbyte(list, i));
				if i==1 then
					b = bit.bxor(b, 31)
				else
					b = bit.bxor(b, 63)
				end
				l2 = l2..GetMaskChar(b);
			end
			link = "|c"..color.."|Htrade:"..id..":".."0"..":450:"..uid..":"..l2.."|h["..name.."]|h|r";

			if(ChatFrameEditBox:IsVisible()) then ChatFrameEditBox:Hide() end;			
			DEFAULT_CHAT_FRAME:AddMessage("所有你缺少的"..name.."配方是："..link);
			DEFAULT_CHAT_FRAME:AddMessage("SHIFT+右鍵點擊技能標題可以得到wowhead網址");
		end
	end
end)


--[[
SetOrHookScript(TradeSkillLinkButton, "OnShow", function(self)
	ChatFrame1:AddMessage(111);
	local link=GetTradeSkillListLink();
	if link then
		ChatFrame1:AddMessage(link);
		WBTradeLink_GetTradeLink(nil, link);
	end
end)
]]

hooksecurefunc("TradeSkillFrame_Update", function(self)
	local link=GetTradeSkillListLink();
	if link then
		WBTradeLink_GetTradeLink(nil, link);
	end
end);
----------
--[[聊天框切换 ChatFrameKeys]]

BINDING_HEADER_CHATFRAMEKEYS = "聊天框切换"
BINDING_NAME_FRAME1 = "第一聊天框"
BINDING_NAME_FRAME2 = "第二聊天框"
BINDING_NAME_FRAME3 = "第三聊天框"
BINDING_NAME_FRAME4 = "第四聊天框"
BINDING_NAME_FRAME5 = "第五聊天框"
BINDING_NAME_FRAME6 = "第六聊天框"
BINDING_NAME_FRAME7 = "第七聊天框"
BINDING_NAME_NEXT = "下个聊天框"
BINDING_NAME_PREV = "上个聊天框"

function ChatFrameKeys_SelectFrame(frame, keyUp)

  if ( not frame:IsShown() and not frame.isDocked) then
    if ( keyUp == 0 ) then
      SELECTED_CHAT_FRAME:AddMessage('|cffffff00聊天框切换:|cffff0000 聊天框'..frame:GetID()..' 不存在。');
    end
    return;
  end

  local chatTab = getglobal("ChatFrame"..frame:GetID().."Tab");

  chatTab:Show();
  SELECTED_CHAT_FRAME = frame;
  if ( frame.isDocked ) then
    FCF_SelectDockFrame(frame);
  end
  if ( keyUp == 1 ) then
    chatTab:Hide();
  end

end

function ChatFrameKeys_NextFrame(keyUp)

  local current;
  local frame;

  current = SELECTED_CHAT_FRAME:GetID();
  frame = SELECTED_CHAT_FRAME;

  if ( keyUp == 0 ) then
    repeat
      current = current + 1;
      if ( current > NUM_CHAT_WINDOWS ) then
        current = 1;
      end
      frame = getglobal("ChatFrame"..current);
    until ( frame:IsShown() or frame.isDocked )
  end

  ChatFrameKeys_SelectFrame(frame, keyUp);

end

function ChatFrameKeys_PrevFrame(keyUp)

  local current;
  local frame;

  current = SELECTED_CHAT_FRAME:GetID();
  frame = SELECTED_CHAT_FRAME;

  if ( keyUp == 0 ) then
    repeat
      current = current - 1;
      if ( current < 1 ) then
        current = NUM_CHAT_WINDOWS;
      end
      frame = getglobal("ChatFrame"..current);
    until ( frame:IsShown() or frame.isDocked )
  end

  ChatFrameKeys_SelectFrame(frame, keyUp);

end




----------
--[[快速变焦 Fastzoom]]

local printstack = -1
function Fastzoomprint(message)
   if(Fastzoomdebug) then
      local stack, filler
      if not message then
	  	--DEFAULT_CHAT_FRAME:AddMessage("No Message to print.")
		 return false 
      end
      printstack=printstack+1
      local filler=""
      for stack=1,printstack do
	  	 filler=filler.."--"
      end   
      if (type(message) == "table") then
	  	-- DEFAULT_CHAT_FRAME:AddMessage("its a table.  length="..SL_tcount(message))
	 	local i
	 	for k,v in pairs(message) do

	    	DEFAULT_CHAT_FRAME:AddMessage(filler.."(key)   "..k)
	    	Fastzoomprint(v)
	 	end
      elseif (type(message) == "userdata") then
      
      else
	  	  if(printstack>0) then
	    	 DEFAULT_CHAT_FRAME:AddMessage(filler.."(value) "..message)
	 	 else
	    	 DEFAULT_CHAT_FRAME:AddMessage(filler..message)
	 	 end
	end
      printstack=printstack-1
   end
end



function Fastzoominitialize()


   --Fastzoomprint("|c00aaffffvariables loaded.  Initializing.")

   local playerName = UnitName("player");
   local serverName = GetCVar("realmName");
   if (playerName == nil or playerName == UNKNOWNOBJECT or playerName == UNKNOWNBEING) then
      return;
   end

   
   if (FASTZOOMSPEED) then                     --old version
   
   else
        Fastzoomprint("设置默认值!")
      --set defaults here
        FASTZOOMSPEED = 5
        SetBinding("CTRL-MOUSEWHEELUP","FastZoomIn")
        SetBinding("CTRL-MOUSEWHEELDOWN","FastZoomOut")
        SaveBindings(2)
   end
   
end



-- ONLOAD, duh
function Fastzoom_OnLoad()

   -- Register for events
   --  this:RegisterEvent("COMBAT_LOG_EVENT_UNFILTERED")
   Fastzoomframe = CreateFrame("Frame")
   Fastzoomframe:RegisterEvent("VARIABLES_LOADED")
   Fastzoomframe:RegisterEvent("UPDATE_BINDINGS")
   
   
   Fastzoomframe:SetScript("OnEvent",Fastzoom_OnEvent)

   --DEFAULT_CHAT_FRAME:AddMessage("FastZoom Loaded.  Type '/Fastzoom X' to change speed")

   -- create our Fastzoomash commands
   SLASH_Fastzoom1 = "/Fastzoom";
   SLASH_Fastzoom2 = "/fastzoom";
   SLASH_Fastzoom3 = "/FZ";
   SLASH_Fastzoom4 = "/fz";
   
   SlashCmdList["Fastzoom"] = Fastzoommain;


   

  	BINDING_HEADER_FastZoom = "快速变焦"
	BINDING_NAME_FastZoomIn = "快速放大"
	BINDING_NAME_FastZoomOut = "快速缩小"




   --Fastzoomprint("|c00449955 end onload ")

   
end 
---------------------------------------------------------------------------

function FastZoomIn()
   CameraZoomIn(FASTZOOMSPEED)
end

function FastZoomOut()
   CameraZoomOut(FASTZOOMSPEED)
end



function Fastzoommain(input)

   --Fastzoomprint("someone did a /Fastzoom")
   
   local binding = GetBindingKey("FastZoomIn")
   if(binding) then
        Fastzoomprint("getkeybinding = "..binding        )
    end
   if not (tonumber(input)) then 
        DEFAULT_CHAT_FRAME:AddMessage("键入 /Fastzoom '数字(范围1-50)'")
   else
        DEFAULT_CHAT_FRAME:AddMessage("变焦速度设置为 "..tonumber(input))
        FASTZOOMSPEED = tonumber(input)
   end
   
   

end

function Fastzoom_OnEvent()
   -- Fastzoomprint("|c00aaffaa  event Triggered!  ")
    Fastzoomprint(event)
    this:UnregisterEvent(event)
   --local timestaFastzoom, event, srcGUID, srcName, srcFlags, dstGUID, dstName, dstFlags = CombatLogGetCurrentEntry()  --for documentation purposes
   --if (event == "VARIABLES_LOADED") then
   if (event == "UPDATE_BINDINGS") then

      Fastzoominitialize()

   end
end



Fastzoom_OnLoad()

----------
--[[技能书按键绑定 mBindings]]
function SpellButton_OnEnter(self)
	local id = SpellBook_GetSpellID(self:GetID());
	if not GetSpellName(id, SpellBookFrame.bookType) then return end;
	local bind1, bind2 = GetBindingKey("SPELL "..GetSpellName(id, SpellBookFrame.bookType));
	GameTooltip:SetOwner(self, "ANCHOR_RIGHT");
	GameTooltip:SetSpell(id, SpellBookFrame.bookType);
	if bind1 then
		if bind2 then
		GameTooltip:AddLine(bind1..", "..bind2, 1, 1, 1);
		else
		GameTooltip:AddLine(bind1, 1, 1, 1);
		end
		GameTooltip:Show();
	end
	--[[if ( GameTooltip:SetSpell(id, SpellBookFrame.bookType) ) then
		self.UpdateTooltip = SpellButton_OnEnter;
	else
		self.UpdateTooltip = nil;
	end]]
end

local function Bindehtiem(self, keyOrButton)
	local mouseFocus = GetMouseFocus();
	if not ( mouseFocus and mouseFocus:GetName():match("SpellButton(%d+)") ) then return end
	
	if ( GetBindingByKey(keyOrButton) == "SCREENSHOT" ) then
		RunBinding("SCREENSHOT");
		return;
	end

	-- Convert the mouse button names
	if ( keyOrButton == "LeftButton" ) then
		keyOrButton = "BUTTON1";
	elseif ( keyOrButton == "RightButton" ) then
		keyOrButton = "BUTTON2";
	elseif ( keyOrButton == "MiddleButton" ) then
		keyOrButton = "BUTTON3";
	elseif ( keyOrButton == "Button4" ) then
		keyOrButton = "BUTTON4"
	elseif ( keyOrButton == "Button5" ) then
		keyOrButton = "BUTTON5"
	end
	
	local keyPressed = keyOrButton;
	
	if ( keyOrButton ) then
		if ( keyOrButton == "BUTTON1" or keyOrButton == "BUTTON2" ) then
			return;
		end
		keyPressed = keyOrButton;
	else
		keyPressed = keyOrButton;
	end
	
	if ( keyPressed == "UNKNOWN" ) then
		return;
	end
	
	if ( keyPressed == "LSHIFT" or
	     keyPressed == "RSHIFT" or
	     keyPressed == "LCTRL" or
	     keyPressed == "RCTRL" or
	     keyPressed == "LALT" or
	     keyPressed == "RALT" ) then
		return;
	end
	
	if ( IsShiftKeyDown() ) then
		keyPressed = "SHIFT-"..keyPressed;
	end
	if ( IsControlKeyDown() ) then
		keyPressed = "CTRL-"..keyPressed;
	end
	if ( IsAltKeyDown() ) then
		keyPressed = "ALT-"..keyPressed;
	end
	
	
	local spellName = GetSpellName(SpellBook_GetSpellID(mouseFocus:GetID()), SpellBookFrame.bookType);
	if spellName then
		if ( keyOrButton == "ESCAPE" ) then
			local key1, key2 = GetBindingKey("SPELL "..spellName);
			if key1 then
				SetBinding(key1);
				DEFAULT_CHAT_FRAME:AddMessage(key1.." |c00b3b3b3已解除绑定|r "..spellName);
			end
			if key2 then
				SetBinding(key2);
				DEFAULT_CHAT_FRAME:AddMessage(key2.." |c00b3b3b3已解除绑定|r "..spellName);
			end
		else
			local oldAction = GetBindingAction(keyPressed);
			if oldAction ~= "" then
				DEFAULT_CHAT_FRAME:AddMessage(keyPressed.." |c00b3b3b3已解除绑定|r "..oldAction);
			end
			SetBindingSpell(keyPressed, spellName);
			DEFAULT_CHAT_FRAME:AddMessage(keyPressed.." |c00b3b3b3已绑定到|r "..spellName);
		end
		SpellButton_OnEnter(mouseFocus);
		SaveBindings(2);

	end
end

local keyFrame = CreateFrame("Button", nil, SpellBookFrame);
 keyFrame:EnableKeyboard();
 keyFrame:Hide();
 keyFrame:SetScript("OnKeyDown", Bindehtiem);

local bindBut = CreateFrame("CheckButton", "bindBut", SpellBookFrame, "UICheckButtonTemplate");
 bindButText:SetText("enable bindings");
 if (GetLocale()=="zhCN") then  bindButText:SetText("技能按键绑定"); elseif (GetLocale() == "zhTW") then  bindButText:SetText("技能按鍵綁定");end
 bindBut:SetPoint("TOPLEFT", 74, -38);
 ShowAllSpellRanksCheckBox:ClearAllPoints();
 ShowAllSpellRanksCheckBox:SetPoint("LEFT", bindButText, "RIGHT", 10, 0);
 bindBut:SetWidth(26);
 bindBut:SetHeight(26);
 bindBut:SetScript("OnMouseUp", function()
	if bindBut:GetChecked() then
		keyFrame:Hide();
	else
		keyFrame:Show();
	end
 end);
 bindBut:SetScript("OnEnter", function(self)
 GameTooltip:SetOwner(self, "ANCHOR_RIGHT");
 GameTooltip:SetText("Click to start/stop binding abilities.\nMouseover an ability and press a button to bind them together.\nPress esc to clear all bindings for an ability.");
if (GetLocale() == "zhCN") then	 GameTooltip:SetText("点击开始/停止绑定设置。\n鼠标移动到技能上按下按键设置绑定。\n按Esc键清除按键绑定。");
elseif (GetLocale() == "zhTW") then  GameTooltip:SetText("點擊開始/停止綁定設置。\n滑鼠移動到技能上按下按鍵設置綁定。\n按Esc鍵清除按鍵綁定。");end
 GameTooltip:Show();
 end);
 bindBut:SetScript("OnLeave", function(self)
 GameTooltip:Hide();
 end);
  
 for i=1, 12 do
	_G["SpellButton"..i]:SetScript("OnMouseDown", function(self, keyPressed)
		if keyFrame:IsShown() then
		if ( keyPressed == "MiddleButton" ) then
			keyPressed = "BUTTON3";
		elseif ( keyPressed == "Button4" ) then
			keyPressed = "BUTTON4"
		elseif ( keyPressed == "Button5" ) then
			keyPressed = "BUTTON5"
		else
			return;
		end

		if ( IsShiftKeyDown() ) then
			keyPressed = "SHIFT-"..keyPressed;
		end
		if ( IsControlKeyDown() ) then
			keyPressed = "CTRL-"..keyPressed;
		end
		if ( IsAltKeyDown() ) then
			keyPressed = "ALT-"..keyPressed;
		end
		local spellName = GetSpellName(SpellBook_GetSpellID(self:GetID()), SpellBookFrame.bookType);
		if spellName then
			if ( keyOrButton == "ESCAPE" ) then
				local key1, key2 = GetBindingKey("SPELL "..spellName);
				local mBindTextF = " |c00b3b3b3已解除绑定|r ";
				local mBindTextT = " |c00b3b3b3已绑定到|r ";
				if key1 then
					SetBinding(key1);
					DEFAULT_CHAT_FRAME:AddMessage(key1.." |c00b3b3b3已解除绑定|r "..spellName);
				end
				if key2 then
					SetBinding(key2);
					DEFAULT_CHAT_FRAME:AddMessage(key2.." |c00b3b3b3已解除绑定|r "..spellName);
				end
			else
				local oldAction = GetBindingAction(keyPressed);
				if oldAction ~= "" then
					DEFAULT_CHAT_FRAME:AddMessage(keyPressed.." |c00b3b3b3已解除绑定|r "..oldAction);
				end
				SetBindingSpell(keyPressed, spellName);
				DEFAULT_CHAT_FRAME:AddMessage(keyPressed.." |c00b3b3b3已绑定到|r "..spellName);
			end
		SpellButton_OnEnter(self);
		SaveBindings(2);
		end
		end
	end)
 end
 
----------
--[[AFK 自动旋转镜头]]
function AfkSpin_OnEvent()
	if event=="ADDON_LOADED" then
		SetCVar("cameraYawMoveSpeed","230")
	elseif event=="CHAT_MSG_SYSTEM" then
		if (arg1 == format(MARKED_AFK_MESSAGE,DEFAULT_AFK_MESSAGE) and GetCVar("autoClearAFK") == "1") then
			SetView(5)
			SetCVar("cameraDistanceMax",50)
			SetCVar("cameraYawMoveSpeed","8")
			MoveViewRightStart()
		elseif arg1 == CLEARED_AFK then
			MoveViewRightStop()
			SetCVar("cameraYawMoveSpeed","230")
			SetCVar("cameraDistanceMax",GetCVar("cameraDistanceMax"))
			SetView(5)
		end
	end
end

local frame = CreateFrame("Frame", "ASFrame");
frame:SetScript("OnEvent", AfkSpin_OnEvent);
frame:RegisterEvent("ADDON_LOADED");
frame:RegisterEvent("CHAT_MSG_SYSTEM");

----------
--[[界面初始化]]
DW_SL_0 = "/console SET useUiScale 1\n/console SET UiScale 0.8\n/console SET scriptErrors 0\n/console SET profanityFilter 0"

--
DW_SL_1 = "\n/sl {Frame = \"Violation0\", SetPoint = {\"BOTTOMRIGHT\", nil, \"BOTTOMRIGHT\", -91, 118}, SetMovable =true}"
DW_SL_2 = "\n/sl {Frame = \"MinimapButtonFrame\", SetPoint = {\"TOPRIGHT\", UIParent, \"TOPRIGHT\", -89, -268}, SetMovable =true}"
DW_SL_3 = "\n/sl {Frame = \"ZOMGBuffsButton\", SetPoint = {\"TOP\", nil, \"TOP\", -263, -118}, SetMovable =true}"
DW_SL_4 = "\n/sl {Frame = \"Steroids\", SetPoint = {\"TOPRIGHT\", nil, \"TOPRIGHT\", -173, -40}, SetMovable =true}"